/*============================================================================*/
/*                        Tortoise Team			                              */
/*============================================================================*/
/*                        OBJECT SPECIFICATION                                */
/*============================================================================*
* C Source:         %tAPP_BackWheels.c%
* Instance:         RPL_1
* %version:         1 %
* %created_by:      Jose Antonio Leon Jazo %
* %date_created:    Sunay September 23 13:24:00 2012 %
*=============================================================================*/
/* DESCRIPTION : C source template file                                       */
/*============================================================================*/
/* FUNCTION COMMENT : This file describes the C source template according to  */
/* the new software platform                                                  */
/*                                                                            */
/*============================================================================*/
/*                               OBJECT HISTORY                               */
/*============================================================================*/
/*  REVISION |   DATE      |                               |      AUTHOR      */
/*----------------------------------------------------------------------------*/
/*  1.0      | 23/10/2012  |                               | Antonio Leon     */
/* Integration under Continuus CM                                             */
/*============================================================================*/

/* Includes */
#include "stdtypedef.h"
#include "HAL_DcMotor.h"
#include "APP_BackWheels.h"
/* -------- */

/* Functions macros, constants, types and datas         */
/* ---------------------------------------------------- */
/* Functions macros */

/*==================================================*/ 
/* Definition of constants                          */
/*==================================================*/ 
/*! 
\def uw_Step
Change of the pwm 
*/
static T_UWORD uw_Step = 2;

/*======================================================*/ 
/* Definition of RAM variables                          */
/*======================================================*/ 

/*======================================================*/ 
/* close variable declaration sections                  */
/*======================================================*/ 

/* Private defines */

/* Private functions prototypes */
void vfnInit_BackWheels(void);
void vfnStop_Motor(T_UWORD uw_channel);
void vfnStart_Motor(T_UWORD uw_channel);
void vfnIncrease_Speed(T_UWORD uw_channel);
void vfnDecrease_Speed(T_UWORD uw_channel);
/* ---------------------------- */


/* Exported functions prototypes */

/* ----------------------------- */

/* Inline functions */
/* ---------------- */

/* Private functions */
/**************************************************************
 *  Name                 :  Jose Antonio Leon Jazo
 *  Description          :	Initialize the back wheels
 *  Parameters           :  [Input, Output, Input / output]
 *  Return               :	void
 *  Critical/explanation :  No
 **************************************************************/
 ///////////////////////////////////////////////////////////////////////
/// \brief Initialize the front wheels of the car 
/////////////////////////////////////////////////////////////////////////
 void vfnInit_BackWheels(void)
 {
 	vfnInit_DcMotor();
 	vfnStop_Motor(2);
 	vfnSet_DcMotor(50, 2);
 	
 }

/**************************************************************
 *  Name                 :  Jose Antonio Leon Jazo
 *  Description          :	Stop left or/and rigth dc motor
 *  Parameters           :  [Input:uw_channel: channel of the dc motor
 *							Output, Input / output]
 *  Return               :	void
 *  Critical/explanation :  No
 **************************************************************/ 
///////////////////////////////////////////////////////////////////////
/// \brief Stop the back wheels
/// \param uw_channel 
/////////////////////////////////////////////////////////////////////////
 void vfnStop_Motor(T_UWORD uw_channel)
 {
 	vfnStop_DcMotor(uw_channel);
 }
 
 
/**************************************************************
 *  Name                 :  Jose Antonio Leon Jazo
 *  Description          :	Start left or/and rigth dc motor
 *  Parameters           :  [Input:uw_channel: channel of the dc motor
 *							Output, Input / output]
 *  Return               :	void
 *  Critical/explanation :  No
 **************************************************************/ 
///////////////////////////////////////////////////////////////////////
/// \brief Start the back wheels
/// \param uw_channel 
///////////////////////////////////////////////////////////////////////// 
 void vfnStart_Motor(T_UWORD uw_channel)
 {
 	vfnStart_DcMotor(uw_channel);
 }
 
/**************************************************************
 *  Name                 :  Jose Antonio Leon Jazo
 *  Description          :	Change the speed of the back wheels
 *  Parameters           :  [Input:uw_speed: speed of the motor, uw_channel: selectin the motor
 *							Output, Input / output]
 *  Return               :	void
 *  Critical/explanation :  No
 **************************************************************/
///////////////////////////////////////////////////////////////////////
/// \brief Increase the speed of the back wheels
/// \param uw_speed
///////////////////////////////////////////////////////////////////////// 
 void vfnIncrease_Speed(T_UWORD uw_channel)
 {
 	T_UWORD uw_CurDuty = vfnGet_Speed(uw_channel);
 	T_UWORD uw_newSpeed = (uw_CurDuty * maxSp)/MAX_US + uw_Step;
 	vfnSet_DcMotor(uw_newSpeed, uw_channel);
 }
/**************************************************************
 *  Name                 :  Jose Antonio Leon Jazo
 *  Description          :	Change the speed of the back wheels
 *  Parameters           :  [Input:uw_speed: speed of the motor, uw_channel: selectin the motor
 *							Output, Input / output]
 *  Return               :	void
 *  Critical/explanation :  No
 **************************************************************/ 
///////////////////////////////////////////////////////////////////////
/// \brief Decrease the speed of the back wheels
/// \param uw_speed
/////////////////////////////////////////////////////////////////////////  
 void vfnDecrease_Speed(T_UWORD uw_channel)
 {
  	T_UWORD uw_CurDuty = vfnGet_Speed(uw_channel);
 	T_UWORD uw_newSpeed = (uw_CurDuty * maxSp)/MAX_US - uw_Step;
 	vfnSet_DcMotor(uw_newSpeed, uw_channel);
 }
 
/**************************************************************
 *  Name                 :  Jose Antonio Leon Jazo
 *  Description          :	Change the speed of the back wheels
 *  Parameters           :  [Input:uw_speed: speed of the motor, uw_channel: selectin the motor
 *							Output, Input / output]
 *  Return               :	void
 *  Critical/explanation :  No
 **************************************************************/ 
///////////////////////////////////////////////////////////////////////
/// \brief change the speed of the back wheels
/// \param uw_speed
/////////////////////////////////////////////////////////////////////////  
 void vfnSet_SpeedBackWheels(T_UWORD uw_newSpeed, T_UWORD uw_channel)
 {
 	vfnSet_DcMotor(uw_newSpeed, uw_channel);
 }
 
/* ----------------- */


/* Exported functions */
/* ------------------ */
